package com.bjx.flow.service.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bjx.flow.domain.entity.FlowGroupEntity;
import com.bjx.flow.domain.query.FlowGroupQuery;
import com.bjx.flow.domain.vo.FlowGroupVO;
import com.bjx.flow.mapper.FlowGroupMapper;
import com.bjx.flow.service.IFlowGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @desc: 流程分组服务实现
 * @author: liushuai
 * @date: 2022/10/24
 */
@Service
public class FlowGroupServiceImpl extends ServiceImpl<FlowGroupMapper, FlowGroupEntity> implements IFlowGroupService {
    @Autowired
    private FlowGroupMapper flowGroupMapper;

    @Override
    public IPage<FlowGroupVO> listFlowGroupPage(FlowGroupQuery flowGroupQuery) {
        IPage<FlowGroupVO> iPage = flowGroupMapper.listFlowGroupPage(flowGroupQuery.getPage(),flowGroupQuery);
        return iPage;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void insertFlowGroup(FlowGroupVO flowGroupVO) {
        FlowGroupEntity entity = Convert.convert(FlowGroupEntity.class, flowGroupVO);
        flowGroupMapper.insert(entity);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void updateFlowGroup(FlowGroupVO flowGroupVO) {
        FlowGroupEntity entity = Convert.convert(FlowGroupEntity.class, flowGroupVO);
         flowGroupMapper.updateById(entity);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void deleteFlowGroupByGroupId(Long groupId) {
        flowGroupMapper.deleteById(groupId);
    }

    @Override
    public FlowGroupVO selectFlowGroupByGroupId(Long groupId) {
        FlowGroupEntity entity = flowGroupMapper.selectById(groupId);
        FlowGroupVO vo = Convert.convert(FlowGroupVO.class,entity);
        return vo;
    }

    @Override
    public List<FlowGroupVO> listFlowGroupAll() {
        List<FlowGroupEntity> list = flowGroupMapper.selectList(new LambdaQueryWrapper<>());
        List<FlowGroupVO> listVos = Convert.toList(FlowGroupVO.class,list);
        return listVos;
    }


}
